//
//  TKYMessageTitleView.m
//  StationHouseHelper
//
//  Created by apple on 2018/6/25.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYMessageTitleView.h"
@interface TKYMessageTitleView()
@property (nonatomic, strong)UIView *line;

@property (nonatomic, strong)UILabel *taskInformationLine;

///**
// 任务消息
// */
//@property (nonatomic, strong)UIButton *taskInformationButton;



@end
@implementation TKYMessageTitleView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.taskInformationButton];
        [self addSubview:self.noticeButton];
        [self addSubview:self.line];
        [self  addSubview:self.taskInformationLine];
        [self taskInformationButtonAction:self.taskInformationButton];
    }
    return self;
}

- (UIButton *)taskInformationButton{
    if (_taskInformationButton == nil) {
        _taskInformationButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_taskInformationButton setTitle:@"任务消息" forState:UIControlStateNormal];
        [_taskInformationButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_taskInformationButton setTitleColor:kRGBColor(32, 136, 252, 1) forState:UIControlStateSelected];

        _taskInformationButton.frame = CGRectMake(kScreenWidth/5, self.kx_height/2- 10, kScreenWidth/5, 20);
        [_taskInformationButton pp_addBadgeWithText:nil];
        [_taskInformationButton pp_moveBadgeWithX:5 Y:0];
        [_taskInformationButton pp_setBadgeHeight:8];
        
        [_taskInformationButton addTarget:self action:@selector(taskInformationButtonAction:) forControlEvents:UIControlEventTouchUpInside];

       // [_taskInformationButton pp_showBadge];
    }
    return _taskInformationButton;
}

- (UIButton *)noticeButton{
    if (_noticeButton == nil) {
        _noticeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_noticeButton setTitle:@"通知提醒" forState:UIControlStateNormal];
        [_noticeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_noticeButton setTitleColor:kRGBColor(32, 136, 252, 1) forState:UIControlStateSelected];

        _noticeButton.frame = CGRectMake(kScreenWidth/5 *3, self.kx_height/2- 10, kScreenWidth/5, 20);
        [_noticeButton pp_addBadgeWithText:nil];
        [_noticeButton pp_moveBadgeWithX:5 Y:0];
        [_noticeButton pp_setBadgeHeight:8];
        
        // [_noticeButton pp_showBadge];
        [_noticeButton addTarget:self action:@selector(noticeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        

    }
    return _noticeButton;
}

- (void)showBadge:(NSNotification *)notification{
      [_noticeButton pp_hiddenBadge];
}

-(UIView *)line {
    if (_line == nil) {
        _line = [[UIView alloc]initWithFrame:CGRectMake(0, self.kx_height-0.5, kScreenWidth, 0.5)];
        _line.backgroundColor = kMainColour;;
    }
    return _line;
}


- (UILabel *)taskInformationLine{
    if (_taskInformationLine == nil) {
        _taskInformationLine = [[UILabel alloc]init];
        _taskInformationLine.backgroundColor = KNavColor;
    }
    return _taskInformationLine;
}


- (void)layoutSubviews{
    [super layoutSubviews];
    _taskInformationLine.kx_height = 2;
    _taskInformationLine.kx_y = self.kx_height - 2;
    [_taskInformationButton.titleLabel sizeToFit];
    _taskInformationLine.kx_width = _taskInformationButton.titleLabel.kx_width;
    _taskInformationLine.kx_centerX = _taskInformationButton.kx_centerX;
}

- (void)taskInformationButtonAction:(UIButton *)button{
     button.selected = YES;
    self.noticeButton.selected = NO;
    //执行动画
    [UIView animateWithDuration:0.25 animations:^{
        _taskInformationLine.kx_centerX = _taskInformationButton.kx_centerX;
    }];

    if (self.taskInformationBlock) {
        self.taskInformationBlock(button);
    }
}

- (void)noticeButtonAction:(UIButton *)button{
     button.selected = YES;
    self.taskInformationButton.selected = NO;
     //执行动画
    [UIView animateWithDuration:0.25 animations:^{
        _taskInformationLine.kx_centerX = _noticeButton.kx_centerX;
    }];
    if (self.noticeBlock) {
        self.noticeBlock(button);
    }
}


@end
